import { get, post } from '../../utils/request'
const state = {
  // 用来保存查询出来的栏目信息
  classify: [],
}

const actions = {
  // 查询所有资讯分类
  findAllClassify(context) {
    // 异步操作
    get("/category/findAll").then((res) => {
      let response = res.data
      context.commit('setClassify', response)
      console.log(res.data);
    });
  },
  // 保存栏目信息
  saveClassify(context, from) {
    let response = post('/category/saveOrUpdate', from)
    return response
  },
  // 删除栏目信息
  deleteClassify(context, id) {
    let response = get('/category/deleteById', id)
    return response
  }
}

const mutations = {
  // 修改state中的值
  setClassify(state, response) {
    state.classify = response
  }
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
}
